package nl.ajonker.railroad.ui.drawcommand;

import java.awt.Graphics2D;
import java.awt.Point;

import nl.ajonker.railroad.ui.Orientation;

public class StraightRailCommand extends DrawCommand {
	private Point a, b;

	public StraightRailCommand() {
		super();
	}

	public StraightRailCommand(Orientation orientaion) {
		super(orientaion);
	}

	@Override
	protected Point calculatePoints() {
		a = new Point(start);
		if (orientation == Orientation.W_E)
			b = new Point(a.x + dimension, a.y);
		if (orientation == Orientation.E_W)
			b = new Point(a.x - dimension, a.y);
		return b;
	}

	@Override
	public synchronized void drawRail(Graphics2D g2d) {
		g2d.setStroke(stroke);
		g2d.setColor(railColor);
		draw(g2d, a, b);

		// int trainLength = dimension / rail.getLength();
		//
		// Point a = new Point(start);
		// Point b = calculateEnd(a, trainLength);
		//
		// for (int i = 0; i < rail.getLength(); i++) {
		// if (rail.hasTrain() && rail.getTrainPosition() == i)
		// g2d.setColor(trainColor);
		// else
		// g2d.setColor(railColor);
		// draw(g2d, a, b);
		// a = new Point(b);
		// b = calculateEnd(b, trainLength);
		// }
		//
		// return a;
	}

	protected Point calculateEnd(Point start, int trainLength) {
		if (orientation == Orientation.W_E)
			return new Point(start.x + trainLength, start.y);
		if (orientation == Orientation.E_W)
			return new Point(start.x - trainLength, start.y);
		return null;
	}

}
